
//Inherit your game's server handler from this class, overriding ProcessUnhandledPacket
class CServer : public Multiplayer<RakServerInterface>
{
public:
	
	CServer(String sHostAddress, unsigned short iServerPort, unsigned short iServerPort);
	virtual ~CServer();
	
	void processPackets() 		{ ProcessPackets(m_pServer); }
	//TODO: Decide whether need this  virtual void send(char* btBitStream, long iLength);
	void getNetworkInterface() 		{ return m_pServer; }
	
protected:
	
private:
	
	RakServerInterface* m_pServer; 		//Instance of the actual RakNet server interface
	
};

/*
template <class interfaceType>
class INetworkState : public Multiplayer<interfaceType>, public IGameState

class CClientPlayState : public INetworkState<RakClientInterface>
class CServerPlayState : public INetworkState<RakServerInterface>
*/
namespace ouden {

class INetworkNode
{
	
public:
	
	/// Called every tick to handle incoming packets
	virtual void processPackets() = 0;
	
	/// Sends the given bitstream over the network to either the server 
	///  (if a client) or all the clients (if the server)
	//TODO: Decide if should have this
	//virtual void send(char* btBitStream, long iLength) = 0;
	
};
/*
struct CPacketHeader {
	bool bTimeStamped;
	unsigned long iTimeStamp;
	unsigned char typeID;
	bool bForward;
};

CPacketHeader getPacketHeader(Packet* pPacket)
{
	
	if ( ( unsigned char ) p->data[ 0 ] == ID_TIMESTAMP )
	{
		if ( p->length > sizeof( unsigned char ) + sizeof( unsigned int ) )
			packetIdentifier = ( unsigned char ) p->data[ sizeof( unsigned char ) + sizeof( unsigned int ) ];
		else
			break;
	}
	else
		packetIdentifier = ( unsigned char ) p->data[ 0 ];
	
}
*/

//Abstract base class for client and server implementations
//Handles packets common to client and server
template <class TNetworkInterface>
class CPeer : public INetworkNode, public Multiplayer<TNetworkInterface>
{
	
public:
	
	
	
protected:
	
	
	
	
};

class CClient : public CPeer<RakClientInterface>
{
public:
	
	CClientMgr(String sHostAddress, unsigned short iServerPort, unsigned short iClientPort);
	virtual ~CClientMgr();
	
	virtual void processPackets() 		{ ProcessPackets(m_pClient); }
	//virtual void send(char* btBitStream, long iLength);
	
protected:
	
	/*
	//If server then forward to all other clients first, then process event
				unsigned char iNetEventType = packet->data[1];
				createNetEvent(iNetEventType, packet->data);
				
	*/
	
	virtual void ProcessUnhandledPacket(Packet *packet, unsigned char packetIdentifier, RakClientInterface *interfaceType)
	{
		
		switch (packetIdentifier) {
			case ID_CHAT : 
				processChatPacket(packet, interfaceType);
				break;
			case 
			default : 
				std::cout << "Unknown packet received with ID: " << packetIdentifier << std::endl;
				break;
				
		}
		
	}
	
private:
	
	void processChatPacket(Packet* pPacket, RakClientInterface* pNetwork)
	{
		
		
		
	}
	
	RakClientInterface* m_pClient;
	
};

class CServerMgr : public INetworkMgr, public Multiplayer<RakServerInterface>
{
public:
	CServerMgr(unsigned short iMaxPlayers, unsigned short iServerPort);
	virtual ~CServerMgr();
	
	virtual void processPackets() 		{ ProcessPackets(m_pServer); }
	virtual void send(char* btBitStream, long iLength);
	
protected:
private:
	
	RakServerInterface* m_pServer;
	
};

} //namespace ouden
